﻿// (c) Copyright Mikhail Dikov. All other rights reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI;
using System.Xml.Serialization;
using System.ComponentModel;
using WebPartExtenders;

namespace WebPartExtenderToolkit
{
    [ToolboxData("<{0}:AlwaysVisibleWebPart runat=server></{0}:AlwaysVisibleWebPart>")]
    [XmlRoot(Namespace = "AlwaysVisibleWebPart")]
    public class AlwaysVisibleWebPart : ExtenderWebPartBase
    {
        private AlwaysVisibleExtender extender;

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            extender = new AlwaysVisibleExtender();
            Controls.Add(extender);
            ChildControlsCreated = true;
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            extender.TargetControlID = this.TargetControlID;
            extender.Enabled = Enabled && !string.IsNullOrEmpty(TargetControlID); 
            extender.BehaviorID = this.BehaviorID;
            extender.ID = this.ID + "extender";
            extender.VerticalSide = VerticalSide;
            extender.HorizontalSide = HorizontalSide;
            extender.VerticalOffset = VerticalOffset;
            extender.HorizontalOffset = HorizontalOffset;
            extender.ScrollEffectDuration = ScrollEffectDuration;
            //Always hide the extender control chrome, because it'll show up as an empty webpart
            ChromeType = PartChromeType.None;
            Title = "Always Visible WebPart Extender";
         }

        #region AlwaysVisibleControlExtender Properies

        // TBD: Make this a drop down in the toolpart
        [Browsable(true),
        WebBrowsable(true),
        WebDisplayName("Vertical Position"),
        WebDescription("Vertical edge of the browser (either Top, Middle, or Bottom) used to anchor the target control. The default is Top."),
        Category("Extender"),
        Personalizable(PersonalizationScope.Shared),
        DisplayName("Vertical Position"),
        Description("Vertical edge of the browser (either Top, Middle, or Bottom) used to anchor the target control. The default is Top.")]
		public VerticalSide VerticalSide{ get; set;}

        // TBD: Make this a drop down in the toolpart
        [Category("Extender"),
        WebBrowsable(true),        
        WebDisplayName("Horizontal Position"),
        WebDescription("Horizontal edge of the browser (either Left, Center, or Right) used to anchor the target control. The default is Left."),
        Browsable(true),
        Personalizable(PersonalizationScope.Shared),
        DisplayName("Horizontal Position"),
        Description("Horizontal edge of the browser (either Left, Center, or Right) used to anchor the target control. The default is Left.")]
        public HorizontalSide HorizontalSide{ get; set;}

        private const int verticalOffsetDefault = 0;
        [Category("Extender"),
        WebBrowsable(true),       
        WebDisplayName("Vertical Offset"),
        WebDescription("Distance to the VerticalSide edge of the browser in pixels from the same side of the target control. The default is 0 pixels."),
        Browsable(true),       
        DefaultValue(verticalOffsetDefault),
        Personalizable(PersonalizationScope.Shared),
        DisplayName("Vertical Offset"),
        Description("Distance to the VerticalSide edge of the browser in pixels from the same side of the target control. The default is 0 pixels.")]
        public int VerticalOffset { get; set; }

        private const int horizontalOffsetDefault = 0;
        [Category("Extender"),
        WebBrowsable(true), 
        WebDisplayName("Horizontal Offset"),
        WebDescription("Distance to the HorizontalSide edge of the browser in pixels from the same side of the target control. The default is 0 pixels."),
        Browsable(true), 
        DefaultValue(horizontalOffsetDefault),
        Personalizable(PersonalizationScope.Shared),
        DisplayName("Horizontal Offset"),
        Description("Distance to the HorizontalSide edge of the browser in pixels from the same side of the target control. The default is 0 pixels.")]
        public int HorizontalOffset { get; set; }

        private const float scrollEffectDurationDefault = 0.1F;
        [Category("Extender"),
        WebBrowsable(true), 
        WebDisplayName("Scroll Effect Duration (s)"),
        WebDescription("Distance to the HorizontalSide edge of the browser in pixels from the same side of the target control. The default is 0 pixels."),
        Browsable(true), 
        DefaultValue(scrollEffectDurationDefault),
        Personalizable(PersonalizationScope.Shared),
        DisplayName("Scroll Effect Duration (s)"),
        Description("Distance to the HorizontalSide edge of the browser in pixels from the same side of the target control. The default is 0 pixels.")]
        public float ScrollEffectDuration{ get; set;}

	    #endregion
   
    }
}
